﻿@model Models.Models.InvoiceList
@using WebApp.Classes

@{
    ViewBag.Title = "Invoices";
    var rights = ViewBag.rights;
}

<table width="100%">
    <tbody>
        <tr>
            <td width="100%" valign="top">
                         
                    <div style="border-style: solid; border-width: 1px; border-color: #DDDDDD"> 
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "StoreName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Store</a>
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DomainName", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Domain</a>
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "SessionDate", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Date</a>                    
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "PopUpFlag", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">PopUp</a>                                        
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "OrderSubmitFlag", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Submitted</a>                                                                                
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "PopUpOrderTotal", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">PopUp Total</a>                                                                                
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "SubmitOrderTotal", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Submitted Total</a>                                                                                
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "BillingPeriodName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Period</a>
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "BillingTypeName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Type</a>
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "BillingUnit", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Unit</a>
                            </th>
                            <th>
                                <a href="@String.Format("Invoices?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "BillingRate", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Rate</a>                                                                                
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        @{
                            foreach (var invoice in Model.List)
                            {                                
                                <tr error='@invoice.BSettError'>                                                                                 
                                    <td>
                                        @invoice.StoreName
                                    </td>
                                    <td>
                                        @invoice.DomainName
                                    </td>
                                    <td>
                                        @invoice.SessionDate.ToString("MM/dd/yyyy hh:mm tt")
                                    </td>
                                    <td>
                                        @(invoice.PopUpFlag ? Html.Raw("<i class=\"icon-check\"></i>") : Html.Raw(""))
                                    </td>
                                    <td>
                                        @(invoice.OrderSubmitFlag ? Html.Raw("<i class=\"icon-check\"></i>") : Html.Raw(""))
                                    </td>
                                    <td>
                                        @invoice.PopUpOrderTotal.ToString("###,###,###.00")
                                    </td>
                                    <td>
                                        @invoice.SubmitOrderTotal.ToString("###,###,###.00")
                                    </td>
                                    <td>
                                        @invoice.BillingPeriodName
                                    </td>
                                    <td>
                                        @invoice.BillingTypeName
                                    </td>
                                    <td>
                                        @invoice.BillingUnit
                                    </td>
                                    <td>
                                        @invoice.BillingRate
                                    </td>
                                </tr>
                                }
                            }
                            <tr>
                                <td colspan="9">
                                    <div class="pagination" style="margin: 0">
                                        <ul>
                                            @{
                                                if (Model.PageIndex > 1)
                                                { 
                                                    <li><a href="@String.Format("Invoices?ubPageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex - 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-left"></i></a></li>
                                                }

                                                for (var i = 1; i <= WebApp.Classes.Statics.GetPages(Model.ResultCount); i++)
                                                {
                                                    if (i == Model.PageIndex)
                                                    {
                                                        <li class="active"><a href="#">@i</a></li>
                                                    }
                                                    else
                                                    {
                                                        <li><a href="@String.Format("Invoices?ubPageIndex={0}&sortColumn={1}&sortDirection={2}", i, Model.SortColumn, Model.SortDirection)">@i</a></li>
                                                    }
                                                }

                                                if (Model.PageIndex != WebApp.Classes.Statics.GetPages(Model.ResultCount) && Model.ResultCount != 0)
                                                { 
                                                    <li><a href="@String.Format("Invoices?ubPageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex + 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-right"></i></a></li>
                                                }                                    
                                            }
                                        </ul>
                                    </div>                        
                                </td>
                                <td colspan="2" style="text-align: right">
                                    <form ></form>
                                    <h5>Records: @Model.ResultCount</h5>
                                </td>
                            </tr>
                        </tbody>                          
                    </table>
                    </div>

                    <br />
                    @{
                        if (new WebApp.Classes.UserRights(ViewBag.Title).FullControl)
                        { 
                        <div class="btn-group">    
                            <span>
                                <button type="button" class="btn btn-inverse" id="bill"><i class="icon-ok-circle icon-white"></i> Bill</button>   
                            </span>
                            <span>
                                <button type="button" class="btn btn-inverse" id="billClose"><i class="icon-ok-sign icon-white"></i> Bill & Close</button>   
                            </span>
                        </div>    
                        }
                    }
            </td>
        </tr>
    </tbody>
</table>      